MAKE                =	make
CC                  =	g++
LINK                =	-g -pedantic -Wall -lstdc++ -lpthread -ldl -lm -Wl,-rpath,.
COMPILE	            =	-g -O0 -D_THREAD_SAFE -pedantic -Wall -c -fPIC -Wno-deprecated
#CLIENT_COMPILE	    =	-g -O0 -D_THREAD_SAFE -pedantic -Wall -c -fPIC -Wno-deprecated -DSOCKET_TCP
#SERVER_COMPILE	    =	-g -O0 -D_THREAD_SAFE -pedantic -Wall -c -fPIC -Wno-deprecated -DSOCKET_UDP
INCPATH             =   ../../include
LIB_DIR             =   ../../lib/linux/
BIN_DIR             =   ../../bin/linux/
GTLOG_LIB_DIR       =   ../../tools/gtlog/lib/Linux/
GTLOG_INCLUDE_DIR   =   ../../tools/log/include/
CLIENT_EXE          =   cppTutorTCPClient
SERVER_EXE          =   cppTutorTCPServer
STATIC_TEST         =   libcppTutorTCPClient.a
SHARED_TEST         =   libcppTutorTCPClient.so
SRCS                =   $(shell ls *.cpp)
SRCS_C              =   $(shell ls *.c)

UDPCLIENTOBJ   	    =   cppTutorSocket.o cppTutorSocketClient.o cppTutorSocketApplication.o
UDPSERVEROBJ        =   cppTutorSocket.o cppTutorSocketServer.o cppTutorSocketApplication.o
SERVER_OBJS         =   $(TCPSERVEROBJ) ../cppTutorMain.o ../cppTutorLog.o
CLIENT_OBJS         =   $(TCPCLIENTOBJ) ../cppTutorMain.o ../cppTutorLog.o
SOCKET_OBJS         =   $(subst .cpp,.o,$(SRCS)) ../cppTutorMain.o ../cppTutorLog.o
OBJS                =   $(subst .cpp,.o,$(SRCS))
OBJS_C              =   $(subst .c,.o,$(SRCS_C))

.SUFFIXES: .o .cpp .c

.cpp.o:
	$(CC) -I $(INCPATH) -I $(GTLOG_INCLUDE_DIR) $(COMPILE) $<

all: tcpClient tcpServer

tcpClient: $(CLIENT_OBJS)
	$(CC) -o $(BIN_DIR)$(CLIENT_EXE) $(CLIENT_OBJS) -L $(GTLOG_LIB_DIR) -L. $(LINK)

tcpServer: $(SERVER_OBJS)
	$(CC) -o $(BIN_DIR)$(SERVER_EXE) $(SERVER_OBJS) -L $(GTLOG_LIB_DIR) -L. $(LINK)

-include depend.mak

depend:
	g++ -MM $(SRCS) > depend.mak

shared: $(OBJS)
	$(CC) -shared -Wl,-soname -lc -o $(LIB_DIR)$(SHARED_TEST) $(OBJS) -L.

static: $(OBJS)
	ar rucvs $(LIB_DIR)$(STATIC_TEST) $(OBJS)

clean:
	rm -rf $(OBJS) depend.mak $(BIN_DIR)$(SERVER_EXE) $(BIN_DIR)$(CLIENT_EXE) $(LIB_DIR)*

cleanapp:
	rm -rf $(BIN_DIR)$(SERVER_EXE) $(BIN_DIR)$(CLIENT_EXE) $(LIB_DIR)*